﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web.UI.WebControls;
using Medianamik.UI.Controls;
using Medianamik.UI.Web.MVP.Presentation;
using Medianamik.UI.Web.MVP.View;
using Medianamik.UI.Web.MVP.View.UserControls;

namespace Medianamik.UI.Web.RedirectManagement.Views
{
    public partial class PublicationsList : PageModuleViewWithPresenter<ModulePresenter<IPublicationsList>>,
                                            IPublicationsList
    {
        BaseModalWindow _typeSelectorWindow = new BaseModalWindow { ID = "TypeSelectorWindow" };
        BaseModalWindow _deleteNodeWindow = new BaseModalWindow { ID = "deleteNodeWindow" };

        public event EventHandler FilterPublications;

        protected void Page_Init(object sender, EventArgs e)
        {
            MyWindowManager.Windows.Add(_deleteNodeWindow);
            MyWindowManager.Windows.Add(_typeSelectorWindow);

            AddArticleButton.Attributes.Add("onClick", "GetRadWindowManager().Open(null, 'TypeSelectorWindow');");
            AddArticleButton.NavigateUrl = "/medianamik/modalwindows/typeselectorwindow.aspx?parentnodeid=" +
                                           Logic.Modules.Articles;

            _typeSelectorWindow.ClientCallBackFunction = "onNodeTypeSelected";
            _typeSelectorWindow.IconUrl = "/Medianamik/images/Icones/Ico_AjoutPage.gif";
            _typeSelectorWindow.ReloadOnShow = true;
            _typeSelectorWindow.Width = Unit.Pixel(400);
            _typeSelectorWindow.Height = Unit.Pixel(200);

            _deleteNodeWindow.IconUrl = "/Medianamik/images/Icones/Ico_Supprimer.gif";
            _deleteNodeWindow.ReloadOnShow = true;
            _deleteNodeWindow.Width = Unit.Pixel(400);
            _deleteNodeWindow.Height = Unit.Pixel(200);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            FilterButton.Click += OnFilterPublicationsButton;
        }

        void OnFilterPublicationsButton(object sender, EventArgs e)
        {
            if (FilterPublications != null)
                FilterPublications(null, null);
        }

        public IMedianamikGrid Grid { get { return PublicationsGrid; } }

        public string AddButtonUrl
        {
            get { return AddArticleButton.NavigateUrl; }
            set { AddArticleButton.NavigateUrl = value; }
        }

        public virtual string Url
        {
            get { return ""; }
        }
    }

    public interface IPublicationsList : IModuleView
    {
        event EventHandler FilterPublications;
        IMedianamikGrid Grid { get; }
        string AddButtonUrl { get; set; }
        string Url { get; }
    }
}